package com.qf.mes.controlller;

import cn.hutool.core.lang.tree.Tree;
import com.qf.mes.entity.MdItemType;
import com.qf.mes.service.MdItemTypeService;
import com.qf.mes.utils.R;

import com.qf.mes.vo.MdItemTypeVO;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.List;

@RestController
public class MdItemTypeController {

    @Resource
    private MdItemTypeService mdItemTypeService;
    @GetMapping("/select1")
    public R select(MdItemType mdItemType){
        List<MdItemTypeVO> select = mdItemTypeService.select(mdItemType);
        return R.ok(select);


    }

    @PostMapping("/add")
    public R insert(@RequestBody MdItemType mdItemType){
        mdItemTypeService.insertMdItemType(mdItemType);
        return R.ok("成功");
    }
    @PostMapping("/update")
    public R update(@RequestBody MdItemType mdItemType){
        mdItemTypeService.UpdateMdItemType(mdItemType);
        return R.ok("成功");
    }
    @GetMapping("/select3")
    public R select3(){
        List<Tree<String>> select = mdItemTypeService.select3();
        return R.ok(select);


    }
    @GetMapping("/ById")
    public R getById(Long itemTypeId){
       MdItemType mdItemType =mdItemTypeService.getMdItemTypeById(itemTypeId);
        return R.ok(mdItemType);


    }
    @GetMapping("/getParentItemType")
    public R getParentItemType(Integer id){
        MdItemType mdItemType =mdItemTypeService.getMdItemTypeByIdName(id);
        return R.ok(mdItemType);


    }




    @PostMapping("/delete")
    public R delete(@RequestParam Integer id){
        mdItemTypeService.deleteMdItemType(id);
        return R.ok("成功");
    }


}
